package com.qboot.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.qboot.common.annotation.LoginLog;
import com.qboot.common.entity.Result;
import com.qboot.system.service.LoginService;
import com.qboot.system.vo.LoginBodyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录
 *
 * @author Tellsea
 * @date 2022/11/25
 */
@Api(tags = "登录")
@RestController
@RequestMapping("/system")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LoginController {

    private final LoginService loginService;

    @ApiOperation("PC端登录")
    @LoginLog("PC端登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginBodyVo entity) {
        return loginService.login(entity);
    }

    @ApiOperation("根据Token获取用户信息")
    @GetMapping("/getInfo")
    public Result getInfo() {
        return loginService.getInfo();
    }

    @ApiOperation("查询菜单")
    @GetMapping("/getMenu")
    public Result getMenu() {
        return loginService.getMenu();
    }

    @ApiOperation("获取登录验证码")
    @GetMapping("/captcha")
    public Result captcha() {
        return loginService.captcha();
    }

    @ApiOperation("注销")
    @GetMapping("/logout")
    public Result logout() {
        StpUtil.logout(StpUtil.getLoginId());
        return Result.ok("注销成功");
    }
}
